package com.example.test.controller;

import com.sankuai.inf.leaf.service.SegmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sankuai.inf.leaf.common.Status;
import com.sankuai.inf.leaf.service.SnowflakeService;

@RestController
@RequestMapping("/leaf")
public class IdController {
    //雪花算法ID
    @Autowired
    private SegmentService snowflakeService;

    @RequestMapping("/snowflake")
    public String getSnowflakeId() {

        //获取snowflake分布式ID
        //id  这个参数是没有意义的，只是为了和号段模式的接口统一，所以要传一个参数，自己随意定义一个
        com.sankuai.inf.leaf.common.Result r =  snowflakeService.getId("id");

        //判断是否成功，成功返回具体的id，不成功返回错误提示
        if(r.getStatus() == Status.SUCCESS) {
            return r.getId()+"";
        }

        return "获取snowflake分布式ID失败";
    }



}
